﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Manager_Default : System.Web.UI.Page
{   
    #region variable
    SqlCommand cmd = null;
    SqlDataReader dr = null;
    Dataconnect conn = new Dataconnect();
    string permission;
    DataDataContext data = new DataDataContext();
    //Dataconnect conn = new Dataconnect();
    #endregion
    #region method

    protected void Mana_login(string user, string password)
    {


        string chuoi = Encript.mahoa(password);
        try
        {
            cmd = new SqlCommand("loginMana", conn.Connect());
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@user", SqlDbType.VarChar).Value = user;
            cmd.Parameters.Add("@pass", SqlDbType.VarChar).Value = chuoi;
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                permission = dr.GetString(2);
                if (permission == "Admin")
                {
                    Response.Write("<script>alert('Admin Log In success')</script>");
                    Session["AdminUserame"] = user;
                    Response.Redirect("AdminManagerBill.aspx");
                }
                else if (permission == "Staff")
                {
                    Response.Write("<script>alert('Admin Log In success')</script>");
                    Session["StaffUserame"] = user;
                    Response.Redirect("StaffManagerBill.aspx");
                }
            }
        }
        catch (Exception ex)
        {
            ex.ToString();
            lbl_error.Visible = true;
            lbl_error.Text = "Username or Password khong dung";

        }

    }
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_login_Click(object sender, EventArgs e)
    {
        Mana_login(txt_username.Text, txt_password.Text);
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Admin Manager Forgot password.aspx");
    }
}